//------------------------------------------------------------------------------
//  <copyright file="KukaLBR4HardwareTests.h" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//  </copyright>
//------------------------------------------------------------------------------

#pragma once

#include "stdafx.h"
#include "KukaLBR4NativeTests.h"
#include "TestResultStringCommon.h"

#include <KukaLBR4PlusController.h>
#include <FriServer.h>

/// <summary> Joint angle target used in CSMD flood test </summary>
const double pCsmdFloodTarget1[NUM_JOINTS] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

/// <summary> Joint angle target used in CSMD flood test
const double pCsmdFloodTarget2[NUM_JOINTS] = {-0.7, 0.2, 0.3, 0.4, 0.5, 0.6, -0.7};

/// <summary> Tests requring presence of Kuka LBR 4+ hardware over a FRI connection. </summary>
class KUKALBR4NATIVETESTS_API KukaLBR4HardwareTests : public TestResultStringCommon
{
public:
	/// <summary> Test that moves the LBR4 to a given joint position </summary>
	/// <param name="pJointGoalPositions"> Target joint positions. </param>
	/// <param name="pMessageHandler"> Controller client message hander for interfacing with with LBR </param>
	static void GoToPositionTest(double pJointGoalPositions[NUM_JOINTS], ControllerClientMessageHandler *pMessageHandler);

	/// <summary> Test that creates an instance of KukaLBR4Controller and moves the LBR4 to a given joint position </summary>
	/// <param name="pJointGoalPositions"> Target joint positions. </param>
	static void GoToPositionTest(double pJointGoalPositions[NUM_JOINTS]);

	/// <summary> Test that moves the LBR4 to a given Cartesian position </summary>
	/// <param name="pCartesianGoalPosition"> Target Cartesian positions. </param>
	/// <param name="pMessageHandler"> Controller client message hander for interfacing with with LBR </param>
	static void GoToCartesianPositionTest(
		double pCartesianGoalPositions[CARTESIAN_FRAME_LENGTH],
		ControllerClientMessageHandler *pMessageHandler);

	/// <summary> Test that creates an instance of KukaLBR4Controller and moves the LBR4 to a given joint position </summary>
	/// <param name="pCartesianGoalPosition"> Target Cartesian positions. </param>
	static void GoToCartesianPositionTest(
		double pCartesianGoalPositions[CARTESIAN_FRAME_LENGTH]);

	/// <summary> Test that data can be received over FRI connection. </summary>
	static void TestFRIConnection();

	/// <summary>
	/// Send a rapid sequence messages to the ControllerClientMessageHandler corresponding to a simple repetitive joint motion
	/// </summary>
	/// <param name="pMsgHandler"> The ControllerclientMessagehandler to interact with. </param>
	/// <param name="pFRIConnection"> FRI Server. </param>
	static void ExecuteJointPositionFloodTest(ControllerClientMessageHandler *pMsgHandler);
};

/// <summary> Move the arm to the "candle" position </summary>
/// <param name="resultString"> buffer for a failure message or indication that test passed. </param>
/// <param name="buffersize"> length of <c>resultString</c> buffer. </param>
extern "C" KUKALBR4NATIVETESTS_API void MoveToCandlePositionTest(char *resultString, int bufferSize);

/// <summary> Move the arm through a test motion using Cartesian impedance control. </summary>
/// <param name="resultString"> buffer for a failure message or indication that test passed. </param>
/// <param name="buffersize"> length of <c>resultString</c> buffer. </param>
extern "C" KUKALBR4NATIVETESTS_API void MoveTestCartesian(char *resultString, int bufferSize);

/// <summary> Passes if data is received over FRI connection </summary>
/// <param name="resultString"> buffer for a failure message or indication that test passed. </param>
/// <param name="buffersize"> length of <c>resultString</c> buffer. </param>
extern "C" KUKALBR4NATIVETESTS_API void TestFRIConnection(char *resultString, int bufferSize);

/// <summary> Test flooding controller running HW with new controller state machine requests.  Effect should be first and last joint rotating back and forth (in candle position) </summary>
/// <param name="resultString"> buffer for a failure message or indication that test passed. </param>
/// <param name="buffersize"> length of <c>resultString</c> buffer. </param>
extern "C" KUKALBR4NATIVETESTS_API void CsmdFloodTest(char *resultString, int bufferSize);
